package com.javasm.service.impl;

import com.javasm.dao.WebUserInfoDao;
import com.javasm.entity.WebUserInfo;
import com.javasm.service.WebUserInfoService;
import com.javasm.utils.MyBatisHeapler;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class WebUserInfoServiceImpl implements WebUserInfoService {

    @Override
    public int addPlyCustomer(WebUserInfo inputCustomer) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        WebUserInfoDao playRoomCategoryDao = sqlSession.getMapper(WebUserInfoDao.class);
        Integer resNum = playRoomCategoryDao.addPlyCustomer(inputCustomer);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }

    @Override
    public int countPlyCustomers(WebUserInfo inputCustomer) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        WebUserInfoDao playRoomCategoryDao = sqlSession.getMapper(WebUserInfoDao.class);
        Integer resNum = playRoomCategoryDao.countPlyCustomers(inputCustomer);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;
    }

    @Override
    public int deletePlyCustomerById(Integer customerId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        WebUserInfoDao playRoomCategoryDao = sqlSession.getMapper(WebUserInfoDao.class);
        Integer resNum = playRoomCategoryDao.deletePlyCustomerById(customerId);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);
        return resNum;

    }

    @Override
    public int editPlyCustomer(WebUserInfo inputCustomer) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        WebUserInfoDao playRoomCategoryDao = sqlSession.getMapper(WebUserInfoDao.class);
        Integer resNum = playRoomCategoryDao.editPlyCustomer(inputCustomer);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);

        return resNum;
    }

    @Override
    public int editPlyCustomerLockout(WebUserInfo inputCustomer) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        WebUserInfoDao playRoomCategoryDao = sqlSession.getMapper(WebUserInfoDao.class);
        Integer resNum = playRoomCategoryDao.editPlyCustomerLockout(inputCustomer);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);

        return resNum;
    }

    @Override
    public WebUserInfo getPlyCustomerById(Integer customerId) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        WebUserInfoDao playRoomCategoryDao = sqlSession.getMapper(WebUserInfoDao.class);
        WebUserInfo customer = playRoomCategoryDao.getPlyCustomerById(customerId);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);

        return customer;
    }

    @Override
    public List<WebUserInfo> listPlyCustomers(WebUserInfo inputCustomer, Integer page, Integer pageSize) {
        SqlSession sqlSession = MyBatisHeapler.getSqlSession();
        WebUserInfoDao playRoomCategoryDao = sqlSession.getMapper(WebUserInfoDao.class);

        List<WebUserInfo> listCustomer = playRoomCategoryDao.listPlyCustomers(inputCustomer, (page-1)*pageSize, pageSize);
        MyBatisHeapler.backAndSaveSqlSession(sqlSession);

        return listCustomer;
    }

}
